;;; This file is part of guix-bavier.git
;;; Copyright © 2020 Eric Bavier <bavier@posteo.net>
;;; License: GPLv3+

(define-module (bavier packages systemd)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix build-system meson)
  #:use-module (gnu packages)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages gperf)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages m4)
  #:use-module (gnu packages pkg-config)
  #:use-module ((guix licenses) #:prefix license:))

(define-public systemd
  (package
    (name "systemd")
    (version "246")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/systemd/systemd.git")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0zrkyxrh5rm45f2l1rnjyv229bcyzawfw7c63jqxwix75px60dyw"))
              (patches (search-patches "bavier/patches/systemd-elide-mkdir.patch"))))
    (build-system meson-build-system)
    (native-inputs
     `(("gettext" ,gnu-gettext)
       ("gperf" ,gperf)
       ("m4" ,m4)
       ("pkg-config" ,pkg-config)))
    (inputs
     `(("libcap" ,libcap)
       ("util-linux" ,util-linux)             ; for `mount`
       ("util-linux:lib" ,util-linux "lib"))) ; for libmount.so
    (arguments
     `(#:tests? #f                      ;Some tests require network, other
                                        ;require starting containers, which
                                        ;fails in our build container.
       #:configure-flags
       (list "-Dcreate-log-dirs=false"
             (string-append "-Drootprefix=" %output)
             (string-append "-Dsysconfdir=" %output "/etc")
             (string-append "-Dsysvinit-path=" %output "/etc/init.d")
             (string-append "-Dsysvrcnd-path=" %output "/etc/rc.d")
             (string-append "-Dtelinit-path=" %output "/lib/sysvinit/telinit")
             (string-append "-Drc-local=" %output "/etc/rc.local")
             ;; Many executables end up depending on libsystemd-shared-*.so,
             ;; which cannot be found with the standard rpath.  This causes
             ;; Guix's validate-runpath phase to fail, so include that
             ;; library's directory in RUNPATH.
             (string-append "-Dc_link_args=-Wl,-rpath=" %output "/lib/systemd"))
       #:phases (modify-phases %standard-phases
                  (add-before 'configure 'patch-hwdb-update
                    (lambda* (#:key outputs #:allow-other-keys)
                      (let ((out (assoc-ref outputs "out")))
                        (substitute* "hwdb.d/meson.build"
                          ;; Do not generate hwdb.bin in /etc/udev, but instead
                          ;; in the output directory.
                          (("systemd-hwdb update" &)
                           (string-append & " --root " out)))
                        #t))))))
    (home-page "https://systemd.io")
    (synopsis "System and Service Manager")
    (description "systemd is a suite of basic building blocks for a Linux
system. It provides a system and service manager that runs as PID 1 and starts
the rest of the system.")
    (license license:lgpl2.1+)))
